package com.example.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.model.pojo.Person;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author zhexueqi
 * @ClassName UserMapper
 * @since 2024/4/3    22:44
 */
@Mapper
public interface UserMapper extends BaseMapper<Person> {

    /**
     * 根据地址获取用户
     * @param address
     * @return
     */
    @Select("select * from user where employee_address = #{address}")
    Person getPersonByAddress(String address);

    /**
     * 根据手机号获取用户
     * @param phone
     * @return Person
     */
    @Select("select * from user where phone = #{phone}")
    Person getPersonByPhone(String phone);

    /**
     * 根据身份证号获取用户
     * @param IdNumber
     * @return
     */
    @Select("select * from user where id_number = #{IdNumber}")
    Person getPersonByIdNumber(String IdNumber);

    /**
     * 添加用户
     * @param person
     * @return
     */
    @Insert("insert into user(name, employee_address, phone, sex, age,employer, id_number, create_time, update_time,sign_security)" +
            "VALUES(#{name},#{employeeAddress},#{phone},#{sex},#{age},#{employer},#{idNumber},#{createTime},#{updateTime},#{signSecurity})")
    Integer addPerson(Person person);

    /**
     * 获取所有用户身份证
     * @return
     */
    @Select("select idNumber from user")
    List<String> getAllByIdNumberStringList();

    @Update("update user set user_type = #{type},sign_security=#{security}  where employee_address = #{address}")
    void updateUser(String type , String address, String security);
    
    /**
     * 根据微信openid获取用户
     * @param openid 微信openid
     * @return 用户信息
     */
    @Select("select * from user where wx_openid = #{openid}")
    Person getPersonByWxOpenId(String openid);

    @Select("select user_type from user where id = #{loginId}")
    int selectRole(int loginId);

}
